package com.tjetc.controller;

import com.tjetc.common.JsonResult;
import com.tjetc.entity.CareRecord;
import com.tjetc.entity.CaregiverInfo;
import com.tjetc.service.CareRecordService;
import com.tjetc.service.CaregiverInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("carerecord")
public class CareRecordController {
    @Autowired
    private CareRecordService careRecordService;

    @RequestMapping("detail/{careId}")
    public JsonResult detail(@PathVariable("careId") Long id) {
        return careRecordService.findById(id);
    }
    @RequestMapping("pageelder")
    public JsonResult pageelder(@RequestParam(value = "name", required = false,defaultValue = "") String name,
                           @RequestParam(value = "pageNo",required = false,defaultValue = "1") Integer pageNo,
                           @RequestParam(value = "pageSize",required = false,defaultValue = "2") Integer pageSize) {
        return careRecordService.findPageElderName(name,pageNo,pageSize);
    }
    @RequestMapping("pagecaregiver")
    public JsonResult pagecaregiver(@RequestParam(value = "name", required = false,defaultValue = "") String name,
                           @RequestParam(value = "pageNo",required = false,defaultValue = "1") Integer pageNo,
                           @RequestParam(value = "pageSize",required = false,defaultValue = "2") Integer pageSize) {
        return careRecordService.findPageCaregiverName(name,pageNo,pageSize);
    }
    @RequestMapping("delete/{careId}")
    public JsonResult delete(@PathVariable("careId") Long id) {
        return careRecordService.deleteById(id);
    }
    //接收参数格式是json
    @RequestMapping("save")
    public JsonResult save(@RequestBody CareRecord careRecord){
        return careRecordService.save(careRecord);
    }
}
